<template>
	<view>
		<view class="xp32-24 address">
			<view class="xflex-x-between boderbom">
				<view class="tags xmr24">{{props.list.contact.substr(0,1)}}</view>
				<view class="xflex1 xflex-x">
					<view class="xflex1 user" @click="goback(props.list)">
						<view class="xflex-x">
							<view class="name xmr24">
								
								{{props.list.contact}}
								
							</view>
							<view class="phone">
								{{hideMobile(props.list.telephone)}}
							</view>
							<view class="s" v-if="props.list.is_default == 1">
								默认
							</view>
						</view>
						<view class="del">
							{{props.list.province}}{{props.list.city}}{{props.list.area}}{{props.list.address}}
						</view>
					</view>
				<image class="edit" src="/static/image/bianji.png" mode="" @click="topage('/pages/mine/address/add?data='+JSON.stringify(props.list))"></image>
				</view>
			</view>
			
			<view class="xflex-x-between xmt24 defaults">
				<view class=" xflex-x" @tap="setDefault(props.list.id)">
					<image  class="defaultsimg" v-if="props.list.is_default == 1" src="/static/image/xuanzhong.png" mode=""></image>
					<image class="defaultsimg" v-else src="/static/image/gouxuan2.png" mode=""></image>
					
					<view class="">
						默认收货地址
					</view>
				</view>
				<view class="" @click="del(props.list.id)">
					删除
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import {
    onReachBottom,
    onShow,
    onLoad
} from '@dcloudio/uni-app';
import {ref,defineProps,defineEmits} from "vue"
import {defultaddress,delAddress} from "@/network/home.js"
const emits = defineEmits(['search','goback'])
// 手机号隐藏中级位数
const hideMobile = (mobile) => {
	if (mobile) {
		return mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
	}
}

// 设置默认地址
const setDefault = (id) => {
	defultaddress({id:id}).then(res => {
		uni.showToast({
			title: '设置默认地址成功',
			icon: 'none'
		})
		// 调用父组件的方法更新页面数据
		emits("updata")

	})
}

function topage(data){
	console.log("111111111");
	uni.navigateTo({
		url:data
	})
}

const goback = (data)=>{
	emits("goback",data)
}
// 删除地址
const del = (id) => {
	delAddress({id:id}).then(res => {
		uni.showToast({
			title: '删除地址成功',
			icon: 'none'
		})
		// 调用父组件的方法更新页面数据
		emits("updata")
	})
}



const props =  defineProps({
	list:{
		type:Array,
		default:['','']
	}
})


</script>


<style lang="scss">
	.tags {
		width: 56rpx;
		height: 56rpx;
		background: #1E50AE10;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #1E50AE;
		line-height: 56rpx;
		text-align: center;
		border-radius: 50%;
	}

	.edit {
		width: 30rpx;
		height: 30rpx;
	}
	.address {
		background-color: #fff;
		border-radius: 16rpx;
	}

	.name {
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		line-height: 45rpx;
	}

	.phone {
		font-size: 24rpx;
		font-weight: 400;
		color: #909090;
		line-height: 33rpx;
	}

	.s {
		font-size: 22rpx;
		font-weight: 400;
		color: #1E50AE;
		padding: 3rpx 11rpx;
		background: #1E50AE10;
		border-radius: 4rpx;
		margin-left: 16rpx;
	}

	.user {
		margin-bottom: 16rpx;

	}

	.del {
		width: 460rpx;
		font-size: 26rpx;
		font-weight: 400;
		color: #333333;
		line-height: 37rpx;
	}
	.boderbom {
		border-bottom:1rpx solid #D8D8D8;
	}
	.defaultsimg {
		width: 28rpx;
		height: 28rpx;
		margin-right: 20rpx;
	}
	.defaults {
		font-size: 24rpx;
		font-weight: 400;
		color: #909090;
		line-height: 33rpx;
	}
</style>